package org.systemsbiology.util;

public class KahanSummation implements Summator {

	private double value = 0;
	private double error = 0;
	
	/* default constructor*/
	
	@Override
	public strictfp void add(double d) {
		double compensated = d - error;
		double sum = value + compensated;
		error = (sum - value) - compensated;
		value = sum;
	}

	@Override
	public double total() {
		return value;
	}

	@Override
	public void clear() {
		value = 0;
		error = 0;
	}

}
